<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="tag" uri="com.sand.myTag" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <input type="hidden" name="rid" id="rid" value="${upContract.rid}">
    <input type="hidden" id="txt" name="txt">
    <div class="layui-form-item">
        <label class="layui-form-label">合同ID</label>
        <div class="layui-input-block">
            <input type="text" name="number" lay-verify="required" disabled value="${upContract.number}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label ">客户</label>
        <div class="layui-input-block">
            <input type="hidden" name="customerId" value="${upContract.customerId}">
            <input type="text" name="customerId1" lay-verify="required" disabled value="${upContract.customerIds}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label ">合同内容</label>
        <div class="layui-input-block">
            <input type="text" name="content" lay-verify="required" placeholder="请输入合同内容" value="${upContract.content}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label ">合同金额</label>
        <div class="layui-input-block">
            <input type="text" name="money" lay-verify="required" placeholder="请输入合同金额" value="${upContract.money}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label ">是否分期</label>
        <div class="layui-input-block">
            <input type="checkbox" name="stages" lay-skin="switch" lay-text="是|否" ${upContract.stages=="是"?"checked":""}>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label ">合同状态</label>
        <div class="layui-input-block">
            <input type="text" name="state" id="state" disabled value="${upContract.state}" class="layui-input layui-input-inline">
            <c:if test="${tag:allow(userAuth, 401003)}"><button class="layui-btn" id="ok"> 通过 </button></c:if>
            <c:if test="${tag:allow(userAuth, 401003)}"><button class="layui-btn layui-btn-normal" id="ord"> 审核中 </button></c:if>
            <c:if test="${tag:allow(userAuth, 401004)}"><button class="layui-btn layui-btn-danger" id="no"> 驳回 </button></c:if>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label ">合同期限</label>
        <div class="layui-input-block">
            <input type="text" name="htEndtime" placeholder="请输入合同期限" value="${upContract.htEndtime}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label ">合同签订时间</label>
        <div class="layui-input-block">
            <input type="text" name="date" id="date" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea id="remarks" name="remarks" class="layui-textarea" placeholder="请输入备注"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
</div>
<script src="${pageContext.request.contextPath}/layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath}/layui/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>

    layui.use(['form', 'tableSelect', 'laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            tableSelect = layui.tableSelect,
            laydate = layui.laydate,
            $ = layui.$;

        $("#remarks").val("${upContract.remarks}");
        $("#date").val("${upContract.date}");
        $("#ok").click(()=>$("#state").val("通过"));
        $("#ord").click(()=>$("#state").val("审核中"));
        $("#no").click(()=>{
            layer.prompt({title: '驳回原因', formType: 2}, function(text, index){
                layer.close(index);
                $("#txt").val(text);
                layer.msg('等待您确认...');
            });
            $("#state").val("驳回");
        });

        laydate.render({
            elem: '#date'
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                url:"${pageContext.request.contextPath}/contract_updateContract",
                type:"post",
                data:"data="+JSON.stringify(data.field),
                dataType:"text",
                success:(rs)=>{
                    if(rs=="OK"){
                        layer.msg("修改成功",{icon:1,time:500},function (){
                            parent.location.reload();
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        })
                    }else{
                        layer.msg("修改失败",{icon:2,time:500})
                    }
                }
            })
        });
        return false;
    });
</script>
</body>
</html>